//
//  PhotoDetailViewController.m
//  艾听歌
//
//  Created by dllo on 16/5/25.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "PhotoDetailViewController.h"
#import "PhotoTableViewCell.h"
#import "photoModel.h"

#define photocell @"cell"

@interface PhotoDetailViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataArray;


@end

@implementation PhotoDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
//    self.view.backgroundColor = [UIColor whiteColor];
    
    NSLog(@"%@",  self.detailsModel.name);
    self.dataArray = [NSMutableArray array];
    
    NSDictionary *action = self.detailsModel.action;
    NSInteger type = [[action objectForKey:@"type"] integerValue];
    if (type == 1) {
        
        NSString *str = [action objectForKey:@"value"];
        UIWebView *wv = [[UIWebView alloc] initWithFrame:self.view.frame];
        
        [self.view addSubview:wv];
        
        //加载数据
        NSURL *url = [NSURL URLWithString:str];
        NSURLRequest *req = [NSURLRequest requestWithURL:url];
        [wv loadRequest:req];
    }else{
        
//        self.tableView = [[BaseTableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
//        self.tableView.delegate = self;
//        self.tableView.dataSource = self;
//        [self.view addSubview:self.tableView];
//        [self.tableView registerClass:[PhotoTableViewCell class] forCellReuseIdentifier:photocell];
        

        
        
//        [self getdata];
    }
    
}

- (void)getdata
{
    
    NSDictionary *action = self.detailsModel.action;
    NSString *value = [action objectForKey:@"value"] ;

    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSString *str = [NSString stringWithFormat:@"http://api.songlist.ttpod.com/songlists/%@?app=ttpod&v=v9.0.1.2016050614&user_id=0&mid=iPhone7%%2C2&f=f320&s=s310&imsi=&hid=&splus=9.3.1&active=1&net=2&openudid=5e6106cc8d5bcf35f60a2997c79a00bb5a7c631f&idfa=ABDADD65-0877-4840-B14F-DFC8D1114AB0&utdid=VzR0dwnWYs8DANbYJ8SsFzOU&alf=(null)&bundle_id=com.ttpod.music&latitude=-1&longtitude=-1&access_token=(null)&vc=9000100", value];
    [manager GET:str parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSLog(@"%@", responseObject);
        
        NSDictionary *dic = [responseObject objectForKey:@"data"];
        NSArray *array = dic[@"singers"];
        for (NSDictionary *smallDic in array) {
            photoModel *model = [[photoModel alloc] init];
            [model setValuesForKeysWithDictionary:smallDic];
            [self.dataArray addObject:model];
        
            NSLog(@"%@",self.dataArray);
        }
        
        [self.tableView reloadData];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"error==%@", error);
    }];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *View = [[UIView alloc] initWithFrame:CGRectMake(0, 175, WIDTH, 40)];
    UIButton *LoveButton = [UIButton buttonWithType:UIButtonTypeCustom];
    LoveButton.frame = CGRectMake(30, 30, 30, 30);
    LoveButton.backgroundColor = [UIColor redColor];
    [View addSubview:LoveButton];
    
    UIButton *shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
    shareButton.frame = CGRectMake(30, 30, 30, 30);
    shareButton.backgroundColor = [UIColor blueColor];
    [View addSubview:shareButton];
    

    View.dk_backgroundColorPicker = DKColorPickerWithRGB(0xffffff, 0x9c9c9c);
    [self.tableView addSubview:View];
    return View;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//    return self.dataArray.count;
    return 20;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    PhotoTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:photocell forIndexPath:indexPath];
    self.tableView.tableHeaderView = cell.Image;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
    
}
@end
